package cz.schovjan.mte_proj.activity;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import cz.schovjan.mte_proj.Constant;
import cz.schovjan.mte_proj.R;
import cz.schovjan.mte_proj.dto.LyricResult;
import cz.schovjan.mte_proj.dto.VideoEntry;
import cz.schovjan.mte_proj.task.SearchVideoTask;

public class VideoActivity extends Activity {

    private LyricResult lr;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.activity_video);
	lr = getIntent().getParcelableExtra(Constant.LYRIC);
	final ListView lv = (ListView) findViewById(R.id.vLvData);
	lv.setOnItemClickListener(new OnItemClickListener() {

	    @Override
	    public void onItemClick(AdapterView<?> adapter, View v, int position, long arg3) {
		// vyhozeni okna s textem pisne
		VideoEntry ve = (VideoEntry) lv.getItemAtPosition(position);
		// toto lze pouzit pouze pokud je nainstalovan youtube na android zarizeni
		// Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("vnd.youtube:" + ve.getUrl()));
		Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(ve.getUrl()));
		startActivity(intent);
	    }
	});
	SearchVideoTask st = new SearchVideoTask(this, lv);
	st.execute(lr);
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
	// Inflate the menu; this adds items to the action bar if it is present.
	getMenuInflater().inflate(R.menu.video, menu);
	return true;
    }
}
